package com.cruise.h5.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cruise.common.web.util.WebUtils;
import com.cruise.h5.mapper.PostCommentMapper;
import com.cruise.h5.mapper.PostMapper;
import com.cruise.h5.pojo.dto.PostCommentDTO;
import com.cruise.h5.pojo.entity.PostComment;
import com.cruise.h5.service.PostCommentService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author cruise
 * @since 2021-03-25
 */
@Service
@Transactional(rollbackFor = RuntimeException.class)
public class PostCommentServiceImpl extends ServiceImpl<PostCommentMapper, PostComment> implements PostCommentService {


    @Resource
    private PostCommentMapper postCommentMapper;

    @Resource
    private PostMapper postMapper;

    @Override
    public void comment(PostCommentDTO postCommentDTO) {
        PostComment postComment = new PostComment(WebUtils.getUserId(), WebUtils.getUserId());
        BeanUtils.copyProperties(postCommentDTO, postComment);
        postCommentMapper.insert(postComment);
        postMapper.addCommentCount(postCommentDTO.getPostId());

    }
}
